#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;

void merge_sort(vector<int>& v, int l, int r)
{
	if (l >= r)
		return;
	int m = l + r >> 1;
	merge_sort(v, l, m);
	merge_sort(v, m + 1, r);
	int i = l, j = m + 1;
	vector<int> cp;
	while (i <= m && j <= r)
	{
		if (v[i] < v[j])
			cp.push_back(v[i++]);
		else
			cp.push_back(v[j++]);
	}

	while (i <= m)
	{
		cp.push_back(v[i++]);
	}
	while (j <= r)
	{
		cp.push_back(v[j++]);
	}
	for (int z = l, x = 0; z <= r; z++, x ++)
	{
		v[z] = cp[x];
	}
}
int main()
{
	vector<int> v = { 7, 9, 567, 0, 56, 2, 45, 1, 45, 12, 34, 2 };

	merge_sort(v, 0, v.size() - 1);

	for (int i = 0; i < v.size(); i++)
		cout << v[i] << ' ';
	return 0;
}